package cn.laniakea.solrj;

import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.HttpSolrServer;
import org.junit.Test;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

public class SolrDelete {
    /**
     * 删除单个
     * @throws IOException
     * @throws SolrServerException
     */
    @Test
    public void testSolrDeleteById() throws IOException, SolrServerException {
        HttpSolrServer solrServer = new HttpSolrServer("http://localhost:8080/solr/core1");
        solrServer.deleteById("94");
        solrServer.commit();
    }

    /**
     * 集合方式删除
     * @throws IOException
     * @throws SolrServerException
     */
    @Test
    public void testSolrDeleteList() throws IOException, SolrServerException {
        HttpSolrServer solrServer = new HttpSolrServer("http://localhost:8080/solr/core1");
        List<String> strList=new ArrayList();
        strList.add("93");
        strList.add("92");
        strList.add("91");
        strList.add("90");
        solrServer.deleteById(strList);
        solrServer.commit();
    }
    /**
     * 根据条件删除
     */
    @Test
    public void testSolrDeleteQuery() throws IOException, SolrServerException {
        HttpSolrServer solrServer = new HttpSolrServer("http://localhost:8080/solr/core1");



        solrServer.deleteByQuery("*:*");
        solrServer.commit();
    }
}
